package Controllers;

import Bean.BeanTeacher;
import Impl.OrderServiceImpl;
import Impl.TeacherServiceImpl;
import cart.ShoppingCart;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Controller
public class OrderAddShiXunController {
	OrderServiceImpl orderService;

    @RequestMapping("/OrderAddShiXun")
	protected void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
    	ApplicationContext applicationContext=(ApplicationContext)request.getSession().getServletContext().getAttribute("ctx");
		orderService=(OrderServiceImpl)applicationContext.getBean("OrderServiceImpl");
		String userid=(String)(request.getSession().getAttribute("userid"));
		String aString='"'+"";
		int class_id=Integer.parseInt(request.getParameter("class_id").replaceAll(aString, ""));
		int student_id=Integer.parseInt(request.getParameter("student_id").replaceAll(aString, ""));
		double class_price=Double.parseDouble(request.getParameter("class_price").replaceAll(aString, ""));
		try {
			orderService.AddOrderShiXun(userid,class_id,student_id,class_price);
			request.getRequestDispatcher("index/orderlist.jsp").forward(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			request.getSession().setAttribute("errmsg", e.getMessage());
			e.printStackTrace();
		}
	}
}
